﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

using iMaker.Library;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblCustomerBLL
    {
        private ItblCustomer IDAL;
        public tblCustomerBLL()
        {
            IDAL = DataAccess.CreateItblCustomer();
        }

        public List<CustomerListENT> GetCustomerDetailList(ref PageParam param, string strPropertyName, string strOrderBy)
        {
            return IDAL.GetCustomerDetailList(ref param, strPropertyName, strOrderBy);
        }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblCustomerBLL GetInstance()
        {
            return new tblCustomerBLL();
        }

        public tblCustomer GetEntity(int UID)
        {
            return IDAL.GetEntity(UID);
        }

        public tblCustomer GetEntity(tblCustomer ent)
        {
            return IDAL.GetEntity(ent);
        }

        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(tblCustomer ent)
        {
            int ret=0;
            if (ent != null)
            {
                try{
                    ret = IDAL.InsertENT(ent);
                }
                catch (Exception er)
                { throw er;}
            }
            return ret;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpDateENT(tblCustomer ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception er)
                {
                    
                    throw;
                }
            }
            return ret;
        }

        /// <summary>
        /// 更新 Customer的Deleted字段
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public int UpdateDeleted(int UID)
        {
            try
            {
                return  IDAL.UpdateDeleted(UID);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 物理删除一条记录
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public int DeleteENT(int UID)
        {
            try
            {
                return IDAL.DeleteENT(UID);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 物理批量删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(tblCustomer ent)
        {
            int ret = 0;
            if (ent!=null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return ret;
        }

        /// <summary>
        /// 根据条件查询返回结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<tblCustomer> GetListByENT(tblCustomer ent, ref PageParam param, string strPropertyName, string strOrderBy)
        {
            List<tblCustomer> list = new List<tblCustomer>();
            if (ent != null && param != null)
            {
                try{
                    list = IDAL.GetListByENT(ent, ref param, strPropertyName, strOrderBy); 
                }
                catch (Exception er)
                { throw er; }
            }
            return list;
        }
        /// <summary>
        /// 根据条件查询返回结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblCustomer> GetListByENT(tblCustomer ent)
        {
            List<tblCustomer> list = new List<tblCustomer>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception er)
                { throw er; }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(tblCustomer ent)
        {
            int Count = 0;
            if (ent != null)
            {
                try
                {
                    Count = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return Count;
        }
        /// <summary>
        /// 判断是否存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(tblCustomer ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
